
#ifndef  DEFS_H
#define  DEFS_H

#include "types.h"
#include "buf.h"
#include "stat.h"

//proc.c
int either_copyout(int user_dst, uint64 dst, void* src, uint len);
int either_copyin(void * dst, int user_src, uint64 src, uint64 len);


//file.c
//void fileinit(void);
//int fileopen(const char * path, int omode);


//fs.c
void fsinit(uint dev) ;

// inode operations
void iinit(void);
struct inode * ialloc(uint dev, short type);
void iupdate(struct inode * ip);
void ilock(struct inode * ip);
void iunlock(struct inode * ip);

// Truncate inode (discard contents).  Caller must hold ip->lock.
void itrunc(struct inode * ip);
void iput(struct inode * ip); //free disk inode & inode->addrs

void iunlockput(struct inode * ip);
struct inode * idup(struct inode * ip);

int readi(struct inode * ip, int user_dst, uint64 dst, uint off, uint n);
int writei(struct inode * ip, int user_src, uint64 src, uint off, uint n);

void stati(struct inode * ip, struct stat * st);

void print_disk_inode(struct dinode * di);


//directory

// find the inode in the directory(dp), and return the de 's offset (*poff)
struct inode * dirlookup(struct inode * dp, char * name, uint *poff); 
int namecmp(const char * s, const char * t);
// find the path 's inode
struct inode * namei(const char * path) ;  
// find the parent inode of name in the path
struct inode * nameiparent(const char * path, char * name) ;  
//write a new directory entry (name, inum) into the directory(dp)
int dirlink(struct inode * dp, char * name, uint inum);



//log.c
void initlog(int dev, int start, int size);

void begin_op(void);
void log_write(struct buf * b);
void end_op(void);
void log_print();

int t__log_outstanding();
int t__log_num();


//bio.c
void binit(void);
void bprint(void);
struct buf * bread(uint dev, uint blockno);
void bwrite(struct buf * b);
void brelse(struct buf* b);
void bpin(struct buf * b);
void bunpin(struct buf * b);

int t__block_in_bcache(uint dev, uint blockno);



// printf.c
#include "printf.h" 

// virtio_disk.c
#include "virtio_disk.h" 



#include <string.h> //user space 



#endif   /* DEFS_H */
